#!/bin/sh

PCDIR="$1"; shift

if [ -z "$PCDIR" ]; then
	PCDIR=.
fi

perl -pi -e 's,-L\S+ *,,gs' $PCDIR/*.pc
perl -pi -e 's,-F\S+ *,,gs' $PCDIR/*.pc
perl -pi -e 's,-I\S+ *,,gs' $PCDIR/*.pc
perl -pi -e 's,^Libs: *,Libs: -F\${libdir} -L\${libdir} ,' $PCDIR/*.pc
perl -pi -e 's,^Cflags: *,Cflags: -F\${libdir} -I\${prefix}/include -I\${includedir} ,' $PCDIR/*.pc
perl -pi -e 's,-l(Qt\S+)_debug,-framework $1,gs' `ls $PCDIR/*.pc | grep -v QtUiTools`
perl -pi -e 's,-l(Qt\S+),-framework $1,gs' `ls $PCDIR/*.pc | grep -v QtUiTools`
perl -pi -e 's| -framework | -Wl,-framework,|gs' `ls $PCDIR/*.pc`

for dir in "$@"; do
	perl -pi -e "s,^(Libs: .*)\$,\$1 -L${dir}/lib," $PCDIR/*.pc
	perl -pi -e "s,^(Cflags: .*)\$,\$1 -I${dir}/include," $PCDIR/*.pc
done
